#include<bits/stdc++.h>
using namespace std;
int t;
int n,m,L,V;
int d,v[100005],a[100005];
int p[100005];
vector<int> answer;
vector<int> ccount;
int main(){
    cin>>t;
    while(t--){
        cin>>n>>m>>L>>V;
        for(int i=1;i<=n;i++){
            cin>>d>>v[i]>>a[i];
        }
        for(int i=1;i<=m;i++){
            cin>>p[i];
        }
        int cnt=0;
        for(int i=1;i<=n;i++){
            if(a[i]==0){
                if(v[i]>V){
                    cnt++;
                }
                ccount.push_back(cnt);
                if(cnt==0){
                    answer.push_back(m);
                }
                answer.push_back(m-1);
            }
        }
    }
    for(int i=0;i<=answer.size()-1;i++){
        cout<<ccount[i]<<" "<<answer[i];
    }
    return 0;
}
